﻿using Abp.Domain.Entities;
using GN.Pay.Core.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Core.Entities
{
    /// <summary>
    /// 交易转账申请
    /// </summary>
    [Table("Trade_TransfersApply")]
    [Serializable]
    public class TradeTransfersApply : Entity<string>, IApplyState
    {
        /// <summary>
        /// 应用Id
        /// </summary>
        [Required]
        [StringLength(maximumLength: 36)]
        public string AppId { get; set; }

        /// <summary>
        /// 申请单号
        /// </summary>
        [Required]
        [StringLength(maximumLength: 32)]
        public string ApplyNo { get; set; }

        /// <summary>
        /// 申请时间
        /// </summary>
        public DateTime ApplyTime { get; set; }

        /// <summary>
        /// 账号
        /// </summary>
        [Required]
        [StringLength(maximumLength: 255)]
        public string AccountNo { get; set; }

        /// <summary>
        /// 收款人户名或真实姓名
        /// </summary>
        [Required]
        [StringLength(maximumLength: 255)]
        public string AccountName { get; set; }

        /// <summary>
        /// 收款人银行代码
        /// </summary>
        public string BankNo { get; set; }

        /// <summary>
        /// 开户行名称
        /// </summary>
        public string OpenBankName { get; set; }

        /// <summary>
        /// 省市
        /// </summary>
        public string ProvinceCity { get; set; }

        /// <summary>
        /// 交易通道Id
        /// </summary>
        [Required]
        public string ChannelId { get; set; }

        /// <summary>
        /// 申请金额
        /// </summary>
        public decimal ApplyMoney { get; set; }

        /// <summary>
        /// 摘要
        /// </summary>
        [Required]
        [StringLength(maximumLength: 255)]
        public string Summary { get; set; }

        /// <summary>
        /// 应用 Ip
        /// </summary>
        public string AppIp { get; set; }

        /// <summary>
        /// 客户端Ip
        /// </summary>
        public string ClientIp { get; set; }

        /// <summary>
        /// 通知地址(Post)
        /// </summary>
        [StringLength(maximumLength: 255)]
        public string NotifyUrl { get; set; }

        /// <summary>
        /// 扩展参数
        /// </summary>
        public string ExtraParam { get; set; }

        /// <summary>
        /// 最后提交时间
        /// </summary>
        public DateTime? LastSubmitTime { get; set; }

        /// <summary>
        /// 申请状态
        /// </summary>
        public int ApplyState { get; set; }

        /// <summary>
        /// 申请状态消息
        /// </summary>
        [Required]
        public string ApplyStateMessage { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public void Validate()
        {
            ApplyMoney = Math.Round(ApplyMoney, 2);
            if (ApplyMoney <= 0)
            {
                PayExceptionUtils.ThrowPayValidationException("申请金客必须大于零。");
            }
           
        }
    }
}
